<template>
    <!-- 总工授权管理 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <a-button class="mb12" icon="plus" type="primary" @click="handleManage(2)" v-btnPermission="'tm_037_add_01'">新增</a-button>
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :page-keys="['pageNo', 'pageSize','totalSize']"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
            <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
            <template slot="action" slot-scope="text, record">
                     <MoreButton>
                    <a @click="handleManage(0, record,true)" v-btnPermission="' tm_037_add_01'">查看</a>
                    <span
                        v-if="
                            record.status != 'SUBMITTED' &&
                            record.status != 'PAST' &&
                            record.status != 'ABOLISH' &&
                            record.status != 'COMMIT'
                        "
                        v-btnPermission="'tm_037_edi_02'"
                    >
                        <a-divider type="vertical" />
                        <a @click="handleManage(1, record)">编辑</a>
                    </span>
                    <template v-if="record.status === 'REJECTED'">
                        <template>
                            <span
                                v-if="record.status == 'DRAFT' || record.status == 'REJECTED'"
                                v-btnPermission="'tm_037_del_03'"
                            >
                                <a @click="handleRemoveParams({ id: record.id })">删除</a>
                            </span>
                            <span
                                v-if="
                                    record.status === 'PAST' ||
                                    record.status === 'SUBMITTED' ||
                                    record.status === 'REJECTED' ||
                                    record.status === 'ABOLISH' ||
                                    record.status === 'COMMIT'
                                "
                                v-btnPermission="'tm_037_loo_04'"
                            >
                                <a-divider type="vertical" />
                                <approval-button :id="record.id" :status="record.status" />
                            </span>
                        </template>
                    </template>
                    <!-- 删除 -->
                    <template v-else>
                        <span
                            v-if="record.status == 'DRAFT' || record.status == 'REJECTED'"
                            v-btnPermission="'tm_037_del_03'">
                            <a-divider type="vertical"></a-divider>
                            <a @click="handleRemoveParams({ id: record.id})">删除</a>
                        </span>
                        <span
                            v-if="
                                record.status === 'PAST' ||
                                record.status === 'SUBMITTED' ||
                                record.status === 'REJECTED' ||
                                record.status === 'ABOLISH' ||
                                record.status === 'COMMIT'
                            "
                            v-btnPermission="'tm_037_loo_04'">
                            <a-divider type="vertical" />
                            <approval-button :id="record.id" :status="record.status" />
                            </span>
                    </template>

                     </MoreButton>
                </template>
                <template slot="status" slot-scope="text, record">
                    <list-status :status="record.status" conversion="en" :is-approval="true" :text="text"/>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import {getGeneralLsit,delGeneral} from '@/api/technical/general'
import BasePage from '@/views/basePage' // 基础配置
import { getAllBranchCompany } from '@/api/commons'
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { typeListApproval,undertake} from './model'
const columns = [
    {title: '序号',dataIndex: 'serial',width: 65,scopedSlots: { customRender: 'serial' }},
    {title: '承接名义',dataIndex: 'undertake',ellipsis: true,width: 150,},
    {title: '实施单位',dataIndex: 'branchComName',ellipsis: true,width: 150,},
    {title: '项目名称',dataIndex: 'projectName',ellipsis: true,width: 150,},
    {title: '授权申请日期',dataIndex: 'authorizationDate',ellipsis: true,width: 250,},
    {title: '申请人',dataIndex: 'applicant',width: 200,ellipsis: true},
    {title: '授权书编号',dataIndex: 'authorizationCode',ellipsis: true, width: 150,},
    {title: '状态',dataIndex: 'status',scopedSlots: { customRender: 'status' },width: 150,},
    {title: '操作',dataIndex: 'action',width: '280px',align: 'center',scopedSlots: { customRender: 'action' },  fixed: 'right',}
]
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable,
    },
    data() {
        this.columns = columns
        return {
            queryParam: {}, // 查询参数
            companyList:[],
            loadData: async (parameter) => {
               if(this.queryParam instanceof Object){
                const requestParameters = Object.assign({}, parameter, { query: this.queryParam,needCount:true});
                  return getGeneralLsit(requestParameters).then((res) => {
                  return res;
                })
               }
            },
            removeApi: { remove: delGeneral,},// api
        }
    },
    computed:{
        searchArr(){
           return [
            {
              name: '所属单位',
              valueKey: 'searchQuery',
              type: OrgTreeSelect,
            },
            // {name: '实施单位', value: 'branchComId',placeholder: '请选择',type: 'select',data: this.companyList},
            // {name: '项目名称',placeholder: '请选择',valueKey: 'projectId',keyValue: 'branchComId',type: SelectProject,isSelf:false,},
            {name: '承接名义',value: 'undertakeId',type: 'select',data: undertake},
            {name: '申请人',type: 'input',value: 'applicant'},
            {name: '授权申请日期',type: 'dateRange',value: 'submitTime',
                attr: {
                    rangeFormat: ['authorizationDateBegin', 'authorizationDateEnd']
                }
            },
            {name: '授权书编号',type: 'input',value: 'authorizationCode'},
            {name: '状态',value: 'status',type: 'select',data: typeListApproval}
        ]
      }
    },
    created() {
      this.querCompany()
    },
    methods: {
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
                query.status = record.status
            }
            this.$router.push({
                path: '/technical/general/updateGeneralAuthorization',
                query
            })
        },
       querCompany() {
        return getAllBranchCompany({tagCodes: ['BC']}).then((res) => {
        let datas = res.data.map((item, index) => {
          return { label: item.name, value: item.id }
        })
        this.companyList = datas
        })
    },
    },
}
</script>
